package com.example.demo2.controller;

import com.example.demo2.entity.City;
import com.example.demo2.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/city")
public class CityController {
    @Autowired  //4.自动注解
    private ICityService iCityService;  //3.定义调用服务层的接口

    //查询所有数据
    @GetMapping
    public List<City> finAll(){
        return iCityService.list();
    }

    //新增
    @PostMapping
    public Boolean add(@RequestBody City city){
        return iCityService.saveOrUpdate(city);

    }
    //删除
    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id){
        return iCityService.removeById(id);
    }

    //根据id查找
    @GetMapping("/{id}")
    public City findById(@PathVariable Integer id){
        return iCityService.getById(id);
    }

    //更新
    @PutMapping("/{id}")
    public Boolean update(@PathVariable Integer id,@RequestBody City city){
        city.setId(id);
        return iCityService.saveOrUpdate(city);
    }






}
